package com.blog.file.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.blog.file.entity.User;
import com.blog.file.mapper.UserMapper;
import com.blog.file.service.UserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.blog.file.utils.OssUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 苏离
 * @since 2022-02-16
 */
@Service
@Slf4j
@Transactional
@SuppressWarnings("all")
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Autowired
    UserMapper userMapper;
    @Autowired
    OssUtil ossUtil;
    @Override
    public boolean setAvatarUrl(String userId, String url) {
        QueryWrapper<User> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("user_id", userId);
        User user=new User();
        user.setUserPhoto(url);
        //User user1 = userMapper.selectOne(queryWrapper);
        //if(!ObjectUtils.isEmpty(user1))
        //ossUtil.delete(user1.getUserPhoto());
        int update = userMapper.update(user, queryWrapper);
        if(update >0)
        return true;
        else
        return false;
    }
}
